<template>
    <div class="app-container">
        <div class="head">
            <img src="@/assets/img/Layout/position.png" />
            <p class="see-block">完工装箱详情</p>
        </div>
        <div class="view-container">
            <el-row class="status-title">
                <el-col :span="3" v-if="planfinishDetailData.status == 1">
                    <el-button
                        class="btn-success width150"
                        type="primary"
                        @click="confirm()"
                        v-hasPermi="['system:planFinish:approveConfirm']"
                    >标记完成</el-button>
                </el-col>
                <el-col :span="3" v-if="planfinishDetailData.status == 0 || planfinishDetailData.status == 1">
                    <el-button
                        class="btn-success ml20"
                        type="primary"
                        @click="onScanCode()"
                    >扫码装箱</el-button>
                </el-col>
                <el-col :span="10" class="status-container">
                    <div class="status-item">
                        <span :class="{ 'active' : planfinishDetailData.status == 0 }">计划中</span>
                        <span :class="{ 'active' : planfinishDetailData.status == 1 }">进行中</span>
                        <span :class="{ 'active' : planfinishDetailData.status == 2 }">已完成</span>
                    </div>
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="12">
                    <span>计划编码：</span>{{ planfinishDetailData.planCode ? planfinishDetailData.planCode : '暂无' }}
                </el-col>
                <el-col :span="12">
                    <span>产品名称：</span>{{ planfinishDetailData.productBasicName ? planfinishDetailData.productBasicName : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="12">
                    <span>产品批号：</span>{{ planfinishDetailData.batchNumber ? planfinishDetailData.batchNumber : '暂无' }}
                </el-col>
                <el-col :span="12">
                    <span>规格：</span>{{ planfinishDetailData.specification ? planfinishDetailData.specification : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="12">
                    <span>箱规：</span>{{ planfinishDetailData.productSpace ? planfinishDetailData.productSpace : '暂无' }}
                </el-col>
                <el-col :span="12">
                    <span>生产序列号：</span>{{ planfinishDetailData.productionSerialNumber ? planfinishDetailData.productionSerialNumber : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="12">
                    <span>计划数量：</span>{{ planfinishDetailData.planNum ? planfinishDetailData.planNum : '暂无' }}
                </el-col>
                <el-col :span="12">
                    <span>完成数量：</span>{{ planfinishDetailData.finishNum ? planfinishDetailData.finishNum : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="12">
                    <span>开实际开始时间：</span>{{ planfinishDetailData.startTime ? planfinishDetailData.startTime : '暂无' }}
                </el-col>
                <el-col :span="12">
                    <span>实际结束时间：</span>{{ planfinishDetailData.endTime ? planfinishDetailData.endTime : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="12">
                    <span>状态：</span>
                    <font v-if="planfinishDetailData.status == 0" style="color:#13C2C2">计划中</font>
                    <font v-if="planfinishDetailData.status == 1" style="color:#13C2C2">进行中</font>
                    <font v-if="planfinishDetailData.status == 2" style="color:#52C41A">已完成</font>
                </el-col>
            </el-row>
        </div>
        <!-- 扫码框 -->
        <input v-model="scanCode"
            class="input-data"
            ref="getFocus"
            type="password"
            @keydown.enter="numberEnterDown()"
            @keyup.enter="numberEnterUp()"
        />
        <!-- 弹出数据 -->
        <el-dialog title="扫码装箱" :visible.sync="open" width="600px" top="100px" append-to-body center :before-close="handleClose" class="dialog-cont">
            <el-row class="dialog-item">
                <el-col :span="12">
                    <span>产品名称：</span>{{ planfinishDetailData.productBasicName ? planfinishDetailData.productBasicName : '暂无' }}
                </el-col>
                <el-col :span="12">
                    <span>规格：</span>{{ planfinishDetailData.specification ? planfinishDetailData.specification : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="dialog-item">
                <el-col :span="12">
                    <span>产品批号：</span>{{ planfinishDetailData.batchNumber ? planfinishDetailData.batchNumber : '暂无' }}
                </el-col>
                <el-col :span="12">
                    <span>箱规：</span>{{ planfinishDetailData.productSpace ? planfinishDetailData.productSpace : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="dialog-item">
                <el-col :span="12">
                    <span>计划数量：</span>{{ planfinishDetailData.planNum ? planfinishDetailData.planNum : '暂无' }}
                </el-col>
                <el-col :span="12">
                    <span>完成数量：</span>{{ planfinishDetailData.finishNum ? planfinishDetailData.finishNum : '暂无' }}
                </el-col>
            </el-row>
            <div class="pack-btn" @click="onMode" :class="{ 'btn-blue' : flag, 'btn-org': !flag}">
                {{ btnText }}
            </div>
            <div class="point">* 点击可切换标准包装/非标准包装</div>
            <div class="packing">
                <p>已包装<span class="number">{{number}}</span>盒</p>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { detailPlanFinish, planFinishConfirm, productToPack } from "@/api/system/planfinish/planfinish"
import { scan } from "@/api/system/scan/scan"
export default {
    name: "planfinishDetail",
    data() {
        return {
            id: '',
            planfinishDetailData: '',
            status: '', // 单据状态
            scanCode: '', // 码
            open: false,
            number: 0, // 装箱数量
            btnText: '标准包装',
            flag: true, // 装箱模式
            remainingNumber: '', // 剩余数量
            packingCode: '', // 母码
            itemCodes: [], // 子码
            scanType: 'PC', // 扫码类型
        }
    },
    created() {
        this.id = this.$route.query.id
        this.getDetailData()
    },
    mounted(){
        if(this.status !== '2'){
            this.$refs.getFocus.focus()
        }
    },
    methods: {
        // 获取详情信息
        getDetailData() {
            detailPlanFinish(this.id).then(res => {
                this.planfinishDetailData = res.data
                this.status = res.data.status
                if(this.status !== '2'){
                    this.open = true
                }else{
                    this.open = false
                }
            })
        },
        // 标记完成
        confirm(){
            this.$modal.confirm('是否确认标记完成？', '标记完成').then(() => {
                planFinishConfirm(this.id).then(res => {
                    if(res.code == 200){
                        this.getDetailData()
                        this.$modal.msgSuccess("操作成功")
                    }
                })
            }).catch(() => {})
        },
        // 扫码装箱
        onScanCode(){
            this.scanCode = ''
            this.open = true
            this.$refs.getFocus.focus()
        },
        // 关闭弹窗
        handleClose(){
            this.open = false
            this.scanCode = ''
        },
        // 装箱模式切换
        onMode(){
            this.flag =! this.flag;
            this.scanCode = ''
            this.$refs.getFocus.focus()
            if(this.flag == true){
                this.btnText = "标准包装"
            }else if(this.flag == false){
                this.btnText = "自定义包装"
            }
        },
        numberEnterDown() {
            this.keyDownTime = new Date().getTime()
        },
        numberEnterUp() {
            this.keyUpTime = new Date().getTime()
            if (this.keyUpTime - this.keyDownTime < 30) {
                // 扫码枪触发
                let data = this.common.codeBoxRule(this.scanCode)
                // 码
                let code = data.code
                // 生产日期
                let productionDate = data.productionDate
                // 失效日期
                let expirationDate = data.expirationDate
                // 装箱数量
                let getNumber = Number(this.planfinishDetailData.productSpace)
                // 是否标准生产 0 标准生产 1 超量生产
                if(this.planfinishDetailData.produceType == '0'){
                    // 标准生产
                    // 剩余数量
                    this.remainingNumber = this.planfinishDetailData.planNum - this.planfinishDetailData.finishNum
                    if(this.remainingNumber && this.remainingNumber > 0){
                        if(code.length == 20){
                            // 码检测
                            scan({code: code, codeType: 0}).then(res => {
                                if(res.code == 200){
                                    this.number ++
                                    // 字码是否存在
                                    if(this.itemCodes.length > 0){
                                        // 装箱模式
                                        if(this.flag == true){
                                            // 标准装箱
                                            // 判断子码总个数
                                            if(code.indexOf('Z') == 0 && this.itemCodes.length < getNumber && this.itemCodes.length < this.remainingNumber){
                                                // 当前子码是否已存在
                                                if(JSON.stringify(this.itemCodes).indexOf(JSON.stringify(code)) > -1){
                                                    this.$modal.msgError("此码重复，请重新扫码！")
                                                    this.number --
                                                    this.scanCode = ''
                                                }else{
                                                    if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                        if(productionDate.length == 6 && expirationDate.length == 6){
                                                            this.itemCodes.push({
                                                                code: code,
                                                                productionDate: productionDate,
                                                                expirationDate: expirationDate,
                                                            })
                                                            this.scanCode = ''
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                            this.scanCode = ''
                                                        }
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }
                                            }else{
                                                if(this.itemCodes.length >= getNumber){
                                                    // 是否是系统母码
                                                    if(code.indexOf('M') == 0){
                                                        if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                            if(productionDate.length == 6 && expirationDate.length == 6){
                                                                this.$modal.loading("正在提交")
                                                                productToPack({
                                                                    planFinishId: this.id,
                                                                    packingCode: code,
                                                                    itemCodes: this.itemCodes,
                                                                    standardOrNo: 0,
                                                                    scanType: this.scanType,
                                                                    productionDate: productionDate,
                                                                    expirationDate: expirationDate,
                                                                }).then(res => {
                                                                    if(res.code == 200){
                                                                        this.scanCode = ''
                                                                        this.number = 0
                                                                        this.itemCodes = []
                                                                        this.$modal.msgSuccess(res.msg)
                                                                        this.getDetailData()
                                                                        this.$modal.closeLoading()
                                                                        this.$refs.getFocus.focus()
                                                                    }else{
                                                                        this.number --
                                                                        this.$modal.msgError(res.msg)
                                                                        this.scanCode = ''
                                                                        this.$modal.closeLoading()
                                                                    }
                                                                })
                                                            }else{
                                                                this.number --
                                                                this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                                this.scanCode = ''
                                                            }
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                            this.scanCode = ''
                                                        }
                                                    }else{
                                                        this.$modal.msgError("母码错误，请重新扫码！")
                                                        this.scanCode = ''
                                                        this.number --
                                                    }
                                                }else{
                                                    this.$modal.msgError("装箱数量不足，请继续！")
                                                    this.scanCode = ''
                                                    this.number --
                                                }
                                            }
                                        }else{
                                            // 非标准装箱
                                            if(code.indexOf('Z') == 0 && this.itemCodes.length < getNumber && this.itemCodes.length < this.remainingNumber){
                                                // 当前子码是否已存在
                                                if(JSON.stringify(this.itemCodes).indexOf(JSON.stringify(code)) > -1){
                                                    this.$modal.msgError("此码重复，请重新扫码！")
                                                    this.number --
                                                    this.scanCode = ''
                                                }else{
                                                    if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                        if(productionDate.length == 6 && expirationDate.length == 6){
                                                            this.itemCodes.push({
                                                                code: code,
                                                                productionDate: productionDate,
                                                                expirationDate: expirationDate,
                                                            })
                                                            this.scanCode = ''
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                            this.scanCode = ''
                                                        }
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }
                                            }else if(code.indexOf('M') == 0){
                                                if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                    if(productionDate.length == 6 && expirationDate.length == 6){
                                                        this.$modal.loading("正在提交")
                                                        productToPack({
                                                            planFinishId: this.id,
                                                            packingCode: code,
                                                            itemCodes: this.itemCodes,
                                                            standardOrNo: 1,
                                                            scanType: this.scanType,
                                                            productionDate: productionDate,
                                                            expirationDate: expirationDate,
                                                        }).then(res => {
                                                            if(res.code == 200){
                                                                this.scanCode = ''
                                                                this.number = 0
                                                                this.itemCodes = []
                                                                this.$modal.msgSuccess(res.msg)
                                                                this.getDetailData()
                                                                this.$modal.closeLoading()
                                                                this.$refs.getFocus.focus()
                                                            }else{
                                                                this.number --
                                                                this.$modal.msgError(res.msg)
                                                                this.scanCode = ''
                                                                this.$modal.closeLoading()
                                                            }
                                                        })
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }else{
                                                this.$modal.msgError("扫码错误，请重新扫码！")
                                                this.scanCode = ''
                                                this.number --
                                            }
                                        }
                                    }else{
                                        // 是否是系统子码
                                        if(code.indexOf('Z') == 0){
                                            if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                if(productionDate.length == 6 && expirationDate.length == 6){
                                                    this.itemCodes.push({
                                                        code: code,
                                                        productionDate: productionDate,
                                                        expirationDate: expirationDate,
                                                    })
                                                    this.scanCode = ''
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }else{
                                                this.number --
                                                this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                this.scanCode = ''
                                            }
                                        }else{
                                            this.number --
                                            this.$modal.msgError("扫码错误，请重新扫码！")
                                            this.scanCode = ''
                                        }
                                    }
                                }else{
                                    this.$modal.msgError(res.msg)
                                    this.scanCode = ''
                                    this.$refs.getFocus.focus()
                                }
                            })
                        }else{
                            this.$modal.msgError("扫码错误，请重新扫码！")
                            this.scanCode = ''
                            this.$refs.getFocus.focus()
                        }
                    }else{
                        this.$modal.msgError("已完成装箱！")
                    }
                }else{
                    // 超量生产
                    if(code.length == 20){
                        // 码检测
                        scan({code: code, codeType: 0}).then(res => {
                            if(res.code == 200){
                                this.number ++
                                // 字码是否存在
                                if(this.itemCodes.length > 0){
                                    // 装箱模式
                                    if(this.flag == true){
                                        // 标准装箱
                                        // 判断子码总个数
                                        if(code.indexOf('Z') == 0 && this.itemCodes.length < getNumber){
                                            // 当前子码是否已存在
                                            if(JSON.stringify(this.itemCodes).indexOf(JSON.stringify(code)) > -1){
                                                this.$modal.msgError("此码重复，请重新扫码！")
                                                this.number --
                                                this.scanCode = ''
                                            }else{
                                                if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                    if(productionDate.length == 6 && expirationDate.length == 6){
                                                        this.itemCodes.push({
                                                            code: code,
                                                            productionDate: productionDate,
                                                            expirationDate: expirationDate,
                                                        })
                                                        this.scanCode = ''
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }
                                        }else{
                                            if(this.itemCodes.length >= getNumber){
                                                // 是否是系统母码
                                                if(code.indexOf('M') == 0){
                                                    if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                        if(productionDate.length == 6 && expirationDate.length == 6){
                                                            this.$modal.loading("正在提交")
                                                            productToPack({
                                                                planFinishId: this.id,
                                                                packingCode: code,
                                                                itemCodes: this.itemCodes,
                                                                standardOrNo: 0,
                                                                scanType: this.scanType,
                                                                productionDate: productionDate,
                                                                expirationDate: expirationDate,
                                                            }).then(res => {
                                                                if(res.code == 200){
                                                                    this.scanCode = ''
                                                                    this.number = 0
                                                                    this.itemCodes = []
                                                                    this.$modal.msgSuccess(res.msg)
                                                                    this.getDetailData()
                                                                    this.$modal.closeLoading()
                                                                    this.$refs.getFocus.focus()
                                                                }else{
                                                                    this.number --
                                                                    this.$modal.msgError(res.msg)
                                                                    this.scanCode = ''
                                                                    this.$modal.closeLoading()
                                                                }
                                                            })
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                            this.scanCode = ''
                                                        }
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }else{
                                                    this.$modal.msgError("母码错误，请重新扫码！")
                                                    this.scanCode = ''
                                                    this.number --
                                                }
                                            }else{
                                                this.$modal.msgError("装箱数量不足，请继续！")
                                                this.scanCode = ''
                                                this.number --
                                            }
                                        }
                                    }else{
                                        // 非标准装箱
                                        if(code.indexOf('Z') == 0 && this.itemCodes.length < getNumber && this.itemCodes.length < this.remainingNumber){
                                            // 当前子码是否已存在
                                            if(JSON.stringify(this.itemCodes).indexOf(JSON.stringify(code)) > -1){
                                                this.$modal.msgError("此码重复，请重新扫码！")
                                                this.number --
                                                this.scanCode = ''
                                            }else{
                                                if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                    if(productionDate.length == 6 && expirationDate.length == 6){
                                                        this.itemCodes.push({
                                                            code: code,
                                                            productionDate: productionDate,
                                                            expirationDate: expirationDate,
                                                        })
                                                        this.scanCode = ''
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }
                                        }else if(code.indexOf('M') == 0){
                                            if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                if(productionDate.length == 6 && expirationDate.length == 6){
                                                    this.$modal.loading("正在提交")
                                                    productToPack({
                                                        planFinishId: this.id,
                                                        packingCode: code,
                                                        itemCodes: this.itemCodes,
                                                        standardOrNo: 1,
                                                        scanType: this.scanType,
                                                        productionDate: productionDate,
                                                        expirationDate: expirationDate,
                                                    }).then(res => {
                                                        if(res.code == 200){
                                                            this.scanCode = ''
                                                            this.number = 0
                                                            this.itemCodes = []
                                                            this.$modal.msgSuccess(res.msg)
                                                            this.getDetailData()
                                                            this.$modal.closeLoading()
                                                            this.$refs.getFocus.focus()
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError(res.msg)
                                                            this.scanCode = ''
                                                            this.$modal.closeLoading()
                                                        }
                                                    })
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }else{
                                                this.number --
                                                this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                this.scanCode = ''
                                            }
                                        }else{
                                            this.$modal.msgError("扫码错误，请重新扫码！")
                                            this.scanCode = ''
                                            this.number --
                                        }
                                    }
                                }else{
                                    // 是否是系统子码
                                    if(code.indexOf('Z') == 0){
                                        if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                            if(productionDate.length == 6 && expirationDate.length == 6){
                                                this.itemCodes.push({
                                                    code: code,
                                                    productionDate: productionDate,
                                                    expirationDate: expirationDate,
                                                })
                                                this.scanCode = ''
                                            }else{
                                                this.number --
                                                this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                this.scanCode = ''
                                            }
                                        }else{
                                            this.number --
                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                            this.scanCode = ''
                                        }
                                    }else{
                                        this.number --
                                        this.$modal.msgError("扫码错误，请重新扫码！")
                                        this.scanCode = ''
                                    }
                                }
                            }else{
                                this.$modal.msgError(res.msg)
                                this.scanCode = ''
                                this.$refs.getFocus.focus()
                            }
                        })
                    }else{
                        this.$modal.msgError("扫码错误，请重新扫码！")
                        this.scanCode = ''
                        this.$refs.getFocus.focus()
                    }
                }
            }else{
                // 直接按键盘触发
                let data = this.common.codeBoxRule(this.scanCode)
                // 码
                let code = data.code
                // 生产日期
                let productionDate = data.productionDate
                // 失效日期
                let expirationDate = data.expirationDate
                // 装箱数量
                let getNumber = Number(this.planfinishDetailData.productSpace)
                // 是否标准生产 0 标准生产 1 超量生产
                if(this.planfinishDetailData.produceType == '0'){
                    // 标准生产
                    // 剩余数量
                    this.remainingNumber = this.planfinishDetailData.planNum - this.planfinishDetailData.finishNum
                    if(this.remainingNumber && this.remainingNumber > 0){
                        if(code.length == 20){
                            // 码检测
                            scan({code: code, codeType: 0}).then(res => {
                                if(res.code == 200){
                                    this.number ++
                                    // 字码是否存在
                                    if(this.itemCodes.length > 0){
                                        // 装箱模式
                                        if(this.flag == true){
                                            // 标准装箱
                                            // 判断子码总个数
                                            if(code.indexOf('Z') == 0 && this.itemCodes.length < getNumber && this.itemCodes.length < this.remainingNumber){
                                                // 当前子码是否已存在
                                                if(JSON.stringify(this.itemCodes).indexOf(JSON.stringify(code)) > -1){
                                                    this.$modal.msgError("此码重复，请重新扫码！")
                                                    this.number --
                                                    this.scanCode = ''
                                                }else{
                                                    if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                        if(productionDate.length == 6 && expirationDate.length == 6){
                                                            this.itemCodes.push({
                                                                code: code,
                                                                productionDate: productionDate,
                                                                expirationDate: expirationDate,
                                                            })
                                                            this.scanCode = ''
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                            this.scanCode = ''
                                                        }
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }
                                            }else{
                                                
                                                if(this.itemCodes.length >= getNumber){
                                                    // 是否是系统母码
                                                    if(code.indexOf('M') == 0){
                                                        if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                            if(productionDate.length == 6 && expirationDate.length == 6){
                                                                this.$modal.loading("正在提交")
                                                                productToPack({
                                                                    planFinishId: this.id,
                                                                    packingCode: code,
                                                                    itemCodes: this.itemCodes,
                                                                    standardOrNo: 0,
                                                                    scanType: this.scanType,
                                                                    productionDate: productionDate,
                                                                    expirationDate: expirationDate,
                                                                }).then(res => {
                                                                    if(res.code == 200){
                                                                        this.scanCode = ''
                                                                        this.number = 0
                                                                        this.itemCodes = []
                                                                        this.$modal.msgSuccess(res.msg)
                                                                        this.getDetailData()
                                                                        this.$modal.closeLoading()
                                                                        this.$refs.getFocus.focus()
                                                                    }else{
                                                                        this.number --
                                                                        this.$modal.msgError(res.msg)
                                                                        this.scanCode = ''
                                                                        this.$modal.closeLoading()
                                                                    }
                                                                })
                                                            }else{
                                                                this.number --
                                                                this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                                this.scanCode = ''
                                                            }
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                            this.scanCode = ''
                                                        }
                                                    }else{
                                                        this.$modal.msgError("母码错误，请重新扫码！")
                                                        this.scanCode = ''
                                                        this.number --
                                                    }
                                                }else{
                                                    this.$modal.msgError("装箱数量不足，请继续！")
                                                    this.scanCode = ''
                                                    this.number --
                                                }
                                            }
                                        }else{
                                            // 非标准装箱
                                            if(code.indexOf('Z') == 0 && this.itemCodes.length < getNumber && this.itemCodes.length < this.remainingNumber){
                                                // 当前子码是否已存在
                                                if(JSON.stringify(this.itemCodes).indexOf(JSON.stringify(code)) > -1){
                                                    this.$modal.msgError("此码重复，请重新扫码！")
                                                    this.number --
                                                    this.scanCode = ''
                                                }else{
                                                    if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                        if(productionDate.length == 6 && expirationDate.length == 6){
                                                            this.itemCodes.push({
                                                                code: code,
                                                                productionDate: productionDate,
                                                                expirationDate: expirationDate,
                                                            })
                                                            this.scanCode = ''
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                            this.scanCode = ''
                                                        }
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }
                                            }else if(code.indexOf('M') == 0){
                                                if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                    if(productionDate.length == 6 && expirationDate.length == 6){
                                                        this.$modal.loading("正在提交")
                                                        productToPack({
                                                            planFinishId: this.id,
                                                            packingCode: code,
                                                            itemCodes: this.itemCodes,
                                                            standardOrNo: 1,
                                                            scanType: this.scanType,
                                                            productionDate: productionDate,
                                                            expirationDate: expirationDate,
                                                        }).then(res => {
                                                            if(res.code == 200){
                                                                this.scanCode = ''
                                                                this.number = 0
                                                                this.itemCodes = []
                                                                this.$modal.msgSuccess(res.msg)
                                                                this.getDetailData()
                                                                this.$modal.closeLoading()
                                                                this.$refs.getFocus.focus()
                                                            }else{
                                                                this.number --
                                                                this.$modal.msgError(res.msg)
                                                                this.scanCode = ''
                                                                this.$modal.closeLoading()
                                                            }
                                                        })
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }else{
                                                this.$modal.msgError("扫码错误，请重新扫码！")
                                                this.scanCode = ''
                                                this.number --
                                            }
                                        }
                                    }else{
                                        // 是否是系统子码
                                        if(code.indexOf('Z') == 0){
                                            if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                if(productionDate.length == 6 && expirationDate.length == 6){
                                                    this.itemCodes.push({
                                                        code: code,
                                                        productionDate: productionDate,
                                                        expirationDate: expirationDate,
                                                    })
                                                    this.scanCode = ''
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }else{
                                                this.number --
                                                this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                this.scanCode = ''
                                            }
                                        }else{
                                            this.number --
                                            this.$modal.msgError("扫码错误，请重新扫码！")
                                            this.scanCode = ''
                                        }
                                    }
                                }else{
                                    this.$modal.msgError(res.msg)
                                    this.scanCode = ''
                                    this.$refs.getFocus.focus()
                                }
                            })
                        }else{
                            this.$modal.msgError("扫码错误，请重新扫码！")
                            this.scanCode = ''
                            this.$refs.getFocus.focus()
                        }
                    }else{
                        this.$modal.msgError("已完成装箱！")
                    }
                }else{
                    // 超量生产
                    if(code.length == 20){
                        // 码检测
                        scan({code: code, codeType: 0}).then(res => {
                            if(res.code == 200){
                                this.number ++
                                // 字码是否存在
                                if(this.itemCodes.length > 0){
                                    // 装箱模式
                                    if(this.flag == true){
                                        // 标准装箱
                                        // 判断子码总个数
                                        if(code.indexOf('Z') == 0 && this.itemCodes.length < getNumber){
                                            // 当前子码是否已存在
                                            if(JSON.stringify(this.itemCodes).indexOf(JSON.stringify(code)) > -1){
                                                this.$modal.msgError("此码重复，请重新扫码！")
                                                this.number --
                                                this.scanCode = ''
                                            }else{
                                                if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                    if(productionDate.length == 6 && expirationDate.length == 6){
                                                        this.itemCodes.push({
                                                            code: code,
                                                            productionDate: productionDate,
                                                            expirationDate: expirationDate,
                                                        })
                                                        this.scanCode = ''
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }
                                        }else{
                                            if(this.itemCodes.length >= getNumber){
                                                // 是否是系统母码
                                                if(code.indexOf('M') == 0){
                                                    if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                        if(productionDate.length == 6 && expirationDate.length == 6){
                                                            this.$modal.loading("正在提交")
                                                            productToPack({
                                                                planFinishId: this.id,
                                                                packingCode: code,
                                                                itemCodes: this.itemCodes,
                                                                standardOrNo: 0,
                                                                scanType: this.scanType,
                                                                productionDate: productionDate,
                                                                expirationDate: expirationDate,
                                                            }).then(res => {
                                                                if(res.code == 200){
                                                                    this.scanCode = ''
                                                                    this.number = 0
                                                                    this.itemCodes = []
                                                                    this.$modal.msgSuccess(res.msg)
                                                                    this.getDetailData()
                                                                    this.$modal.closeLoading()
                                                                    this.$refs.getFocus.focus()
                                                                }else{
                                                                    this.number --
                                                                    this.$modal.msgError(res.msg)
                                                                    this.scanCode = ''
                                                                    this.$modal.closeLoading()
                                                                }
                                                            })
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                            this.scanCode = ''
                                                        }
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }else{
                                                    this.$modal.msgError("母码错误，请重新扫码！")
                                                    this.scanCode = ''
                                                    this.number --
                                                }
                                            }else{
                                                this.$modal.msgError("装箱数量不足，请继续！")
                                                this.scanCode = ''
                                                this.number --
                                            }
                                        }
                                    }else{
                                        // 非标准装箱
                                        if(code.indexOf('Z') == 0 && this.itemCodes.length < getNumber){
                                            // 当前子码是否已存在
                                            if(JSON.stringify(this.itemCodes).indexOf(JSON.stringify(code)) > -1){
                                                this.$modal.msgError("此码重复，请重新扫码！")
                                                this.number --
                                                this.scanCode = ''
                                            }else{
                                                if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                    if(productionDate.length == 6 && expirationDate.length == 6){
                                                        this.itemCodes.push({
                                                            code: code,
                                                            productionDate: productionDate,
                                                            expirationDate: expirationDate,
                                                        })
                                                        this.scanCode = ''
                                                    }else{
                                                        this.number --
                                                        this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                        this.scanCode = ''
                                                    }
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }
                                        }else if(code.indexOf('M') == 0){
                                            if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                                if(productionDate.length == 6 && expirationDate.length == 6){
                                                    this.$modal.loading("正在提交")
                                                    productToPack({
                                                        planFinishId: this.id,
                                                        packingCode: code,
                                                        itemCodes: this.itemCodes,
                                                        standardOrNo: 1,
                                                        scanType: this.scanType,
                                                        productionDate: productionDate,
                                                        expirationDate: expirationDate,
                                                    }).then(res => {
                                                        if(res.code == 200){
                                                            this.scanCode = ''
                                                            this.number = 0
                                                            this.itemCodes = []
                                                            this.$modal.msgSuccess(res.msg)
                                                            this.getDetailData()
                                                            this.$modal.closeLoading()
                                                            this.$refs.getFocus.focus()
                                                        }else{
                                                            this.number --
                                                            this.$modal.msgError(res.msg)
                                                            this.scanCode = ''
                                                            this.$modal.closeLoading()
                                                        }
                                                    })
                                                }else{
                                                    this.number --
                                                    this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                    this.scanCode = ''
                                                }
                                            }else{
                                                this.number --
                                                this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                this.scanCode = ''
                                            }
                                        }else{
                                            this.$modal.msgError("扫码错误，请重新扫码！")
                                            this.scanCode = ''
                                            this.number --
                                        }
                                    }
                                }else{
                                    // 是否是系统子码
                                    if(code.indexOf('Z') == 0){
                                        if(!isNaN(Number(productionDate)) && !isNaN(Number(expirationDate))){
                                            if(productionDate.length == 6 && expirationDate.length == 6){
                                                this.itemCodes.push({
                                                    code: code,
                                                    productionDate: productionDate,
                                                    expirationDate: expirationDate,
                                                })
                                                this.scanCode = ''
                                            }else{
                                                this.number --
                                                this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                                this.scanCode = ''
                                            }
                                        }else{
                                            this.number --
                                            this.$modal.msgError("扫码获取日期不正确，请重新扫码！")
                                            this.scanCode = ''
                                        }
                                    }else{
                                        this.number --
                                        this.$modal.msgError("扫码错误，请重新扫码！")
                                        this.scanCode = ''
                                    }
                                }
                            }else{
                                this.$modal.msgError(res.msg)
                                this.scanCode = ''
                                this.$refs.getFocus.focus()
                            }
                        })
                    }else{
                        this.$modal.msgError("扫码错误，请重新扫码！")
                        this.scanCode = ''
                        this.$refs.getFocus.focus()
                    }
                }
            }
        },
    }
}
</script>
<style scoped>
::v-deep .el-dialog__body{
    padding: 0 25px;
}
::v-deep .el-dialog__header{
    padding: 20px 0 30px;
}
.dialog-item {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: #222;
    padding-bottom:30px;
}
.pack-btn{
    width:180px;
    height:35px;
    line-height: 35px;
    font-size: 16px;
    color:#fff;
    text-align: center;
    border-radius: 5px;
    transition: all .5s linear;
    cursor: pointer;
}
.btn-blue{
    background: #5ED4D4;
}
.btn-org{
    background: #ff8b65;
}
.packing{
    padding: 20px 0;
    font-size: 13px;
    line-height: 30px;
    text-align:center;
    color: #222222;
}
.number{
    font-size: 110px;
    line-height: 110px;
    font-weight: 500;
    color: #5ED4D4;
    margin: 0 50px;
}
.point {
    padding: 10px 0 0;
    font-size: 14px;
    color: #f00;
}
</style>

